﻿using System;
using System.Collections.Generic;
using System.Text;
using lin;

/// <summary>
/// 服务器游戏网络数据
/// </summary>
public class GameHandler
{
    public GameHandler(Dictionary<Protocol, Handler> handlers)
    {
        handlers.Add(Protocol.ReqReady,OnReady);
        handlers.Add(Protocol.ReqRob, OnRob);
        handlers.Add(Protocol.ReqNotRob, OnNotRob);
        handlers.Add(Protocol.ReqPutCard,OnPutCard);
        handlers.Add(Protocol.ReqPassCard,OnPassCard);

        handlers.Add(Protocol.ReqRestart,OnRestart);
    }


    //玩家准备
    private void OnReady(UserToken token, byte[] bytes)
    {
        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.SetReady(token);
    }

    //抢
    private void OnRob(UserToken token, byte[] bytes)
    {
        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.RobLandlord(token);
    }
    //不抢
    private void OnNotRob(UserToken token, byte[] bytes)
    {
        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.NotRobLandlord(token);
    }
    //玩家出牌
    private void OnPutCard(UserToken token, byte[] bytes)
    {
        ReqPais req = Util.Deserialize<ReqPais>(bytes);

        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.PutCard(req);
    }

    //玩家要不起
    private void OnPassCard(UserToken token, byte[] bytes)
    {
        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.PassPutCard(token);
    }

    //玩家重新开始
    private void OnRestart(UserToken token, byte[] bytes)
    {
        Room rm = RoomManager.Instance.GetRoom(token.user.roomId);
        rm.Restart(token);
    }
}
